/*
package com.gxa.gateway.filter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

*/
/**
 * 自定义的全局过滤器（作用是统一鉴权）
 * 必须实现接口GlobalFilter, Ordered里面的两个方法
 *//*

@Component
@Slf4j
public class AuthGlobalFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        try {// 获取请求头
            HttpHeaders headers = exchange.getRequest().getHeaders();
            List<String> authorization = headers.get("Authorization");
            if (authorization == null || StringUtils.isEmpty(authorization.get(0))){
                ServerHttpResponse response = exchange.getResponse();
                log.info("token不能为空！");
                Map map = new HashMap<>();
                map.put("code",1001);
                map.put("msg","token不能为空！");
                ObjectMapper objectMapper = new ObjectMapper();
                String resStr = objectMapper.writeValueAsString(map);
                // 设置响应头
                response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
                response.setStatusCode(HttpStatus.UNAUTHORIZED);
                // 转换buffer
                DataBuffer wrap = response.bufferFactory().wrap(resStr.getBytes());
                return response.writeWith(Mono.just(wrap));
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return chain.filter(exchange);
    }

    */
/**
     * 标识当前过滤器的优先级，返回值越小，优先级越高
     * @return
     *//*

    @Override
    public int getOrder() {
        return 0;
    }
}*/
